package three.templateexample;

import java.io.UnsupportedEncodingException;

public class StringDisplay extends AbstractDisplay{
    private String string;
    private int width;
    public StringDisplay(String s){
        this.string = s;
        try {
            this.width = s.getBytes("Shift_JIS").length;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void open() {
        System.out.println("长度："+width);
        printLine();
    }

    @Override
    public void print() {
        System.out.println("|" + string + "|");
    }

    @Override
    public void close() {
        printLine();
    }
    private void printLine(){
        System.out.print("+");
        for(int i=0; i < width; i++){
            System.out.print("-");
        }
        System.out.println("+");
    }
}
